<template>
  <el-container v-loading="loading">

    <el-row>
      <el-button
        icon="fa fa-fw fa-refresh"
        size="mini"
        type="info"
        @click="handleRefresh">
      </el-button>

      <el-button
        icon="fa fa-fw fa-check"
        size="mini"
        type="success"
        @click="handleApplyAccept"> 同意申请
      </el-button>
    </el-row>

    <el-table
      @selection-change="handleSelectionChange"
      :data="tableData"
      tooltip-effect="dark"
      border
      :default-sort="{prop: 'date', order: 'descending'}"
      :row-class-name="tableRowClassName"
      size="small">
      <el-table-column
        type="selection"
        fixed="left"
        width="55">
      </el-table-column>

      <el-table-column
        prop="real_name"
        width="120"
        label="真实姓名">
      </el-table-column>

      <el-table-column
        prop="work_number"
        width="120"
        label="工号">
      </el-table-column>

      <el-table-column
        prop="work_phone"
        width="120"
        label="工作电话	">
      </el-table-column>

      <el-table-column
        prop="emergency"
        width="120"
        label="紧急联系人	">
      </el-table-column>

      <el-table-column
        prop="id_card"
        width="150"
        label="身份证号"
        sortable>
      </el-table-column>

      <el-table-column
        prop="been_driving"
        label="驾龄"
        width="120"
        sortable>
      </el-table-column>

      <el-table-column
        prop="city"
        label="注册城市"
        width="120"
        sortable>
      </el-table-column>

      <el-table-column
        prop="id_card_pic.id_card_pic"
        label="身份证正面"
        width="100"
        show-overflow-tooltip>
        <template slot-scope="scope">
          <img :src="scope.row.id_card_pic.id_card_pic" class="logo-img">
        </template>
      </el-table-column>

      <el-table-column
        prop="id_card_pic.id_card_fpic"
        label="身份证反面"
        width="100"
        show-overflow-tooltip>
        <template slot-scope="scope">
          <img :src="scope.row.id_card_pic.id_card_fpic" class="logo-img">
        </template>
      </el-table-column>


      <el-table-column
        prop="period"
        label="驾证有效期"
        width="120"
        sortable>
      </el-table-column>

      <el-table-column
        prop="driving_license.driverPhoto"
        label="驾照正面照片"
        width="100"
        show-overflow-tooltip>
        <template slot-scope="scope">
          <img :src="scope.row.driving_license.driverPhoto" class="logo-img">
        </template>
      </el-table-column>

      <el-table-column
        prop="driving_license.driverfPhoto"
        label="驾照反面照片"
        width="100"
        show-overflow-tooltip>
        <template slot-scope="scope">
          <img :src="scope.row.driving_license.driverfPhoto" class="logo-img">
        </template>
      </el-table-column>
      <el-table-column
        prop="xszz"
        label="行驶证正面"
        width="100"
        show-overflow-tooltip>
        <template slot-scope="scope">
          <img :src="scope.row.xszz" class="logo-img">
        </template>
      </el-table-column>

      <el-table-column
        prop="xszf"
        label="行驶证反面"
        width="100"
        show-overflow-tooltip>
        <template slot-scope="scope">
          <img :src="scope.row.xszf" class="logo-img">
        </template>
      </el-table-column>
      <el-table-column
        prop="clzp"
        label="车辆照片"
        width="100"
        show-overflow-tooltip>
        <template slot-scope="scope">
          <img :src="scope.row.clzp" class="logo-img">
        </template>
      </el-table-column>
      <el-table-column
        prop="yyzgz"
        label="运营资格证"
        width="100"
        show-overflow-tooltip>
        <template slot-scope="scope">
          <img :src="scope.row.yyzgz" class="logo-img">
        </template>
      </el-table-column>
      <el-table-column
        prop="jdk"
        label="监督卡"
        width="100"
        show-overflow-tooltip>
        <template slot-scope="scope">
          <img :src="scope.row.jdk" class="logo-img">
        </template>
      </el-table-column>
      <el-table-column
        prop="czczp"
        label="出租车"
        width="100"
        show-overflow-tooltip>
        <template slot-scope="scope">
          <img :src="scope.row.czczp" class="logo-img">
        </template>
      </el-table-column>
      <el-table-column
        prop="create_time"
        label="申请时间"
        width="180"
        sortable>
        <template slot-scope="scope">
          <i class="fa fa-clock-o fa-fw"></i>
          <span style="margin-left: 10px">{{ scope.row.create_time }}</span>
        </template>
      </el-table-column>

      <el-table-column
        prop="audit"
        label="审核状态"
        width="120"
        sortable>
        <template slot-scope="scope">
          <el-tag v-if="scope.row.audit==0">待审核</el-tag>
          <el-tag v-if="scope.row.audit==1">审核通过</el-tag>
          <el-tag v-if="scope.row.audit==2">审核拒绝</el-tag>
        </template>
      </el-table-column>

      <el-table-column
        label="操作"
        fixed="right"
        width="300">
        <template slot-scope="scope">
          <el-button
            icon="fa fa-fw fa-eye"
            size="mini"
            type="info"
            title="查看详情"
            @click="handleDataView(scope.$index, scope.row)">
            查看详情
          </el-button>

          <el-button
            icon="fa fa-fw fa-check"
            size="mini"
            type="success"
            title="同意"
            @click="handleApplyAcceptItem(scope.$index, scope.row)">
            同意
          </el-button>

          <el-button
            icon="fa fa-fw fa-remove"
            size="mini"
            type="danger"
            title="拒绝"
            @click="handleApplyReject(scope.$index, scope.row)">
            拒绝
          </el-button>

        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pagination.currentPage"
      :page-sizes="pagination.pageSizes"
      :page-size="pagination.pageSize"
      :total="pagination.total"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <!-- 提示 -->
    <el-dialog
      title="数据详情"
      :visible.sync="dialogVisible"
      width="700px">
      <div v-if="currentDataIndex != null">
        <!--
        create_time:'',                //类型：String  必有字段  备注：申请时间
        sex:'',                //类型：Number  必有字段  备注：无-->

        <p><span class="label">真实姓名：</span>{{tableData[currentDataIndex].real_name}}</p>
        <p><span class="label">工号：</span>{{tableData[currentDataIndex].work_number}}</p>
        <p><span class="label">工作电话：</span>{{tableData[currentDataIndex].work_phone}}</p>
        <p><span class="label">紧急联系人：</span>{{tableData[currentDataIndex].emergency}}</p>
        <p><span class="label">身份证：</span>{{tableData[currentDataIndex].id_card}}</p>
        <p><span class="label">驾龄：</span>{{tableData[currentDataIndex].been_driving}}</p>
        <p><span class="label">注册城市：</span>{{tableData[currentDataIndex].city}}</p>
        <p>
          <span class="label">身份证正面：</span>
          <img :src="tableData[currentDataIndex].id_card_pic.id_card_pic" class="big-img">
        </p>
        <p>
          <span class="label">身份证反面：</span>
          <img :src="tableData[currentDataIndex].id_card_pic.id_card_fpic" class="big-img">
        </p>
        <p><span class="label">驾证有效期：</span>{{tableData[currentDataIndex].period}}</p>
        <p>
          <span class="label">驾照正：</span>
          <img :src="tableData[currentDataIndex].driving_license.driverPhoto" class="big-img">
        </p>
        <p>
          <span class="label">驾照反：</span>
          <img :src="tableData[currentDataIndex].driving_license.driverfPhoto" class="big-img">
        </p>
         <p>
          <span class="label">行驶证正：</span>
          <img :src="tableData[currentDataIndex].xsz.Photo" class="big-img">
        </p>
        <p>
          <span class="label">行驶证反：</span>
          <img :src="tableData[currentDataIndex].xsz.fPhoto" class="big-img">
        </p>
         <p>
          <span class="label">车辆照片：</span>
          <img :src="tableData[currentDataIndex].clzp" class="big-img">
        </p>
        <p>
          <span class="label">运营资格证：</span>
          <img :src="tableData[currentDataIndex].yyzgz" class="big-img">
        </p>
         <p>
          <span class="label">监督卡：</span>
          <img :src="tableData[currentDataIndex].jdk" class="big-img">
        </p>
        <p>
          <span class="label">出租车照：</span>
          <img :src="tableData[currentDataIndex].czczp" class="big-img">
        </p>
        <p><span class="label">申请时间：</span>{{tableData[currentDataIndex].create_time}}</p>
      </div>
      <!--<p><span class="label">类型：</span>
        <el-tag v-if="tableData[currentDataIndex].type==1">跑腿</el-tag>
        <el-tag v-if="tableData[currentDataIndex].type==2">代驾</el-tag>
        <el-tag v-if="tableData[currentDataIndex].type==3">家政</el-tag>
      </p>-->
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">关 闭</el-button>
      </span>
    </el-dialog>

  </el-container>
</template>

<script>
  export default {
    mounted: function () {
      this.getData();
    },
    methods: {
      /**
       * 数据请求
       * */
      getData: function () {
        let _this = this;
        this.api.getDriverApplyList({
          page: this.pagination.currentPage,
          paginate: this.pagination.pageSize
        }).then(function (res) {
          if (res.code == 1) {
            _this.tableData = res.data.data;
            _this.pagination.total = res.data.total;
          }
          _this.loading = false;
        }).catch(function (res) {
          throw new Error(res);
        });
      },
      /**
       * 分页数改变
       */
      handleSizeChange: function (pageSize) {
        this.pagination.pageSize = pageSize;
        this.getData();
      },
      /**
       * 当前页面改变
       * @param currentPage
       */
      handleCurrentChange: function (currentPage) {
        this.pagination.currentPage = currentPage;
        this.getData();
      },
      /**
       * 数据刷新
       */
      handleRefresh: function () {
        this.getData();
        this.$message({
          showClose: true,
          message: '刷新成功',
          type: 'success'
        });
      },
      /**
       * 批量同意启用
       */
      handleApplyAccept: function () {
        let _this = this;
        let arr = [];
        if (this.multipleSelection.length <= 0) {
          _this.$message({
            showClose: true,
            message: '暂无选中',
            type: 'warning'
          });
        }
        for (let i = 0; i < this.multipleSelection.length; i++) {
          arr.push(this.multipleSelection[i].id);
        }
        this.$confirm('此操作将同意该申请, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.api.getDriverAudit2Array({id: JSON.stringify(arr)}).then(function (res) {
            if (res.code == 1) {
              _this.getData();
              _this.$message({
                showClose: true,
                message: res.msg,
                type: 'success'
              });
            } else {
              _this.$message({
                showClose: true,
                message: res.msg,
                type: 'warning'
              });
            }
          }).catch(function (error) {
            throw new Error(error);
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消该操作'
          })
        })
      },
      /**
       * 同意申请
       */
      handleApplyAcceptItem(index, row) {
        let _this = this;
        let _id = row.id;
        this.$confirm('此操作将同意该申请, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          _this.api.getDriverAudit2Item({id: _id, audit: 1}).then(function (res) {
            if (res.code == 1) {
              _this.getData();
              _this.$message({
                showClose: true,
                message: res.msg,
                type: 'success'
              });
            } else {
              _this.$message({
                showClose: true,
                message: res.msg,
                type: 'warning'
              });
            }
          }).catch(function (error) {
            throw new Error(error);
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消该操作'
          })
        })
      },
      /**
       * 拒绝申请
       * @param index
       * @param row
       */
      handleApplyReject(index, row) {
        let _this = this;
        let _id = row.id;
        this.$prompt('请输入拒绝原因', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(({value}) => {
          _this.api.getDriverAudit2Item({id: _id, audit: 2, why: value}).then(function (res) {
            if (res.code == 1) {
              _this.getData();
              _this.$message({
                showClose: true,
                message: res.msg,
                type: 'success'
              });
            } else {
              _this.$message({
                showClose: true,
                message: res.msg,
                type: 'warning'
              });
            }
          }).catch(function (error) {
            throw new Error(error);
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消操作'
          });
        });
      },
      /**
       * 数据视图
       * */
      handleDataView: function (index, row) {
        this.currentDataIndex = index;
        this.dialogVisible = true;
      },
      /**
       * 表格选中状态记录
       * @param val
       */
      handleSelectionChange(val) {
        this.multipleSelection = val;
      }
    },
    data() {
      return {
        loading: true,  // 页面加载
        tableData: [],
        multipleSelection: [],
        pagination: {
          total: 5,
          currentPage: 1,
          pageSize: 10,
          pageSizes: [5, 10, 20, 25, 30, 50, 100],
        },
        dialogVisible: false,   // 弹框
        currentDataIndex: null,
      }
    },
  }
</script>

<style scoped>
  .el-container {
    display: block;
  }

  .el-table, .el-row {
    width: 98% !important;
    margin: 15px auto;
  }

  .el-pagination {
    text-align: center;
    margin: 15px 0;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }

  .logo-img {
    width: 40px;
    height: 40px;
  }

  .label {
    width: 100px;
    display: inline-block;
    text-align: right;
    margin-right: 15px;
  }

  .big-img {
    width: 400px;
    height: 200px;
  }
</style>
